package com.t3.tuio
{
	import flash.geom.Point;

	public class TUIOTrail extends TUIOCursor 
	{
		private var _points:Array = new Array();
		private var _color:Number;
		private var firstUpdate:Boolean = true;
		
		public function TUIOTrail( event:TUIOEvent ):void
		{	
			_color = Math.random() * 0xFFFFFF;
			this.graphics.lineStyle( 20, _color );
			super( event );
		}
		
		public override function update( event:TUIOEvent, ignoreEvent:Boolean = false ):void
		{	
			if( ignoreEvent || event.s_id == this.s_id && ( event.x != _x || event.y != _y ) )
			{
				super.update( event );
				
				var point:Point = new Point( event.xStage, event.yStage );
				
				if( firstUpdate )
				{
					this.graphics.moveTo( point.x, point.y );
					firstUpdate = false;
				}
				
				this.graphics.lineTo( point.x, point.y );
				this.graphics.moveTo( point.x, point.y );	
				
				if( this is TUIOTrail )
				{
					event.data.point = this;
					this.dispatchEvent( new TUIOEvent( TUIOEvent.CURSOR_MOVED, event.data ) );
				}
				
				_points.push( point );
			}
		}
		
		public function get color():Number
		{
			return _color;
		}
		
		public function get points():Array
		{
			return _points;
		}
	}
}